<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>{$basic.title}</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link href="__LAYUI__/css/layui.css" rel="stylesheet">
    <link href="__LAYUI__/css/ah.css" rel="stylesheet">
</head>
<body>
<div class="wrapper-content">
<div class="ibox">
	<div class="ibox-title"><h3>权限编辑</h3>
	<div class="ibox-tools">
		</div>
	</div>
	<div class="ibox-content">
		<form class="layui-form" enctype="multipart/form-data" id="amData" action="{:url('auth/edit')}">

				<div class="layui-form-item">
					  <label class="layui-form-label">用户名</label>
					  <div class="layui-input-inline">
						<input type="text" value="{$user.username}"  class="layui-input" disabled="">
					  </div>
					</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
					<div id="LAY-auth-tree-index"></div>
					</div>
				</div>
				<input type="text" name="id" value="{$user.id}" class="layui-hide">
				<input type="text" name="admin" value="{$user.admin}" class="layui-hide">
	<button type="button" class="layui-btn" lay-submit lay-filter="saveData">保存提交</button>
	</form>
	</div>
</div>
</div>
</body>
<script src="__LAYUI__/layui.js"></script>
<script>
layui.config({
	base: '__LAYUI__/exts/',
}).extend({
	authtree: 'authtree',
});
	layui.use(['jquery', 'authtree','form', 'layer'], function(){
		
	  var $ = layui.jquery;
	  var authtree = layui.authtree;
	  var form = layui.form;
	  var layer = layui.layer;
	  var xaoam ={
		  	  close:function(msg){
		  		  layer.msg(msg);
		  		  if(parent.length > 0){
		  			  let index = parent.layer.getFrameIndex(window.name);
		  			  parent.layer.close(index);
		  			  parent.Wxaoam.init();
		  		  }
		  		  
		  	  },
		  	  tool:function(){
		  			form.on('submit(saveData)', function(data){
		  				var action = $(this).parent('form').attr('action');
		  				var index = parent.layer.getFrameIndex(window.name);
		  				var Fdata = new FormData(document.getElementById("amData"));
		  				$.ajax({
		  					url:action,
		  					data:Fdata,
		  					dataType:'json',
		  					type:'POST',
		  					contentType: false,
		  					processData: false,
		  					success:function(res){
		  						if(res.code == 200){
		  							xaoam.close(res.msg);
		  						}else{
		  							layer.msg(res.msg);
		  						}
		  					}
		  				})
		  			  return false; 
		  			});
		  	  },
		  init:function(){
			    $.ajax({
			      url: "{:url('node/lists')}",
			      dataType: 'json',
			      success: function(data){
			  	  var trees = authtree.listConvert(data.data, {
			  	      primaryKey: 'id'
			  	      ,startPid: 0
			  	      ,parentKey: 'parentId'
			  	      ,nameKey: 'node_name'
			  	      ,valueKey: 'id'
					  ,checkedKey:{$checked}
			  	  });
				  
			        authtree.render('#LAY-auth-tree-index', trees, {
			          inputname: 'ids[]'
			          ,layfilter: 'lay-check-auth'
			          ,'theme': 'auth-skin-default'
			          ,'themePath': '__LAYUI__/exts/themes/'
			          ,autowidth: true
			        });
			  	 }
			  });
		  }
	  } 
		xaoam.init();// 初始化
		xaoam.tool();
		window.Wxaoam = xaoam;
	});
</script>

</html>
